package com.example.dairenkun.neufoodshop.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dairenkun.neufoodshop.R;
import com.example.dairenkun.neufoodshop.activity.AddCommentActivity;
import com.example.dairenkun.neufoodshop.activity.FoodDetailActivity;
import com.example.dairenkun.neufoodshop.bean.Order;
import com.example.dairenkun.neufoodshop.service.OrderService;
import com.squareup.picasso.Picasso;

import java.util.List;

public class OrderListAdapter extends RecyclerView.Adapter<ViewHolder> {
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;
    public OrderListAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_myorder, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
       final Order entity=(Order) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.food_name.setText(entity.getFoodname());
       viewHolder.food_price.setText(entity.getPrice()+"元");
        viewHolder.order_time.setText(entity.getOrdertime());
        //  添加评论
        viewHolder.btn_comment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(mContext, AddCommentActivity.class);
                intent.putExtra("order_id",entity.getOrder_id()+"");
                intent.putExtra("shopname",entity.getShopname());
                intent.putExtra("foodname",entity.getFoodname());
                intent.putExtra("price",entity.getPrice()+"");
                intent.putExtra("food_id",entity.getFood_id()+"");
                mContext.startActivity(intent);
            }
        });
        //点击进入详情
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(mContext,FoodDetailActivity.class);
                intent.putExtra("food_id",entity.getFood_id()+"");
                mContext.startActivity(intent);

            }
        });
    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView food_name;
        TextView food_price;
        Button btn_comment;
        TextView order_time;



        public ViewHolder(View itemView) {
            super(itemView);
            food_name = (TextView) itemView.findViewById(R.id.order_food_name);
            food_price = (TextView) itemView.findViewById(R.id.order_food_money);
            order_time=(TextView) itemView.findViewById(R.id.order_time);
            btn_comment=(Button)itemView.findViewById(R.id.btn_myorder_cancel);

        }

    }
}
